package com.tesserate.pmt;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.text.DecimalFormat;
import java.text.Format;

public class Label extends TextLobby {

	private static final long serialVersionUID = 8852289850967327319L;
	private double valor = 0;
	private MouseAdapter mouseListener;
	
	private Format format = new DecimalFormat("#####0");
	private double valorMaximo = 999;
	
	public Label(int valor, int x, int y) {
		init(valor, x, y);
	}

	public Label(int valor, int x, int y, Font font) {
		this.font = font;
		init(valor, x, y);
	}

	public Label(int valor, int x, int y, Font font, Color c) {
		this.font = font;
		this.color = c;
		init(valor, x, y);
	}

	public Label(String msg, int x, int y, Font font, Color c) {
		this.font = font;
		this.color = c;
		this.msg = msg;
		setVisivel(true);
		this.setIgnoreRepaint(true);
		this.setFocusable(false);
	}
	
	private void init(int valor, int x, int y) {
		this.setIgnoreRepaint(true);
		this.setFocusable(false);
		this.valor = valor;
		setVisivel(true);
		posicao.setLocation(x, y);
		this.msg = String.valueOf(valor);
	}

	@Override
	public void render(Graphics2D g) {
		paint(g);
	}

	@Override
	public void paint(Graphics g){
		if (!isVisible()) return; 
		redefineBonds(g);
		g.setFont(font);
		g.setColor(color);
		msg = format.format(valor);
		if ( alignment == RIGHT_ALIGNMENT){
			g.drawString(msg, posicao.getLocation().x-fm.stringWidth(msg), posicao.getLocation().y);
		}else{
			g.drawString(msg, posicao.getLocation().x, posicao.getLocation().y);
		}
		/*g.setColor(Color.yellow);
		Rectangle r = getBounds();
		g.drawRect(r.x, r.y, r.width, r.height);*/
	}
	
	public double getValor() {
		return valor;
	}

	public void setValor(double valor) {
		this.valor = valor;
		msg = String.valueOf(valor);
	}

	public Format getNumberFormat() {
		return format;
	}

	public void setNumberFormat(Format format) {
		this.format = format;
	}

	public MouseAdapter getMouseListener() {
		return mouseListener;
	}

	public void addValor(double incremento){
		this.valor += incremento;
		if(this.valor < 0) this.valor = 0;
		if(this.valor > valorMaximo) this.valor = valorMaximo;
		//msg = String.valueOf(this.valor);
	}

	public double getValorMaximo() {
		return valorMaximo;
	}

	public void setValorMaximo(double valorMaximo) {
		this.valorMaximo = valorMaximo;
	}

}
